// 测试统一字段结构的脚本
import Mock from 'mockjs'

// 随机图片服务
const getRandomImage = (width, height, category = '') => {
  const baseUrl = 'https://images.unsplash.com'
  const categories = {
    drama: [
      'photo-1529626455594-4ff0802cfb7e',
      'photo-1535713875002-d1d0cf377fde',
      'photo-1507003211169-0a1dd7228f2d',
      'photo-1438761681033-6461ffad8d80',
      'photo-1508214751196-bcfd4ca60f91',
      'photo-1518676590629-3dcbd9c5a5c9',
      'photo-1544725176-7c40e5a71c5e',
      'photo-1573496359142-b8d87734a5a2',
      'photo-1507003211169-0a1dd7228f2d',
      'photo-1536440136628-849c177e76a1'
    ],
    avatar: [
      'photo-1535713875002-d1d0cf377fde',
      'photo-1507003211169-0a1dd7228f2d',
      'photo-1438761681033-6461ffad8d80',
      'photo-1508214751196-bcfd4ca60f91'
    ]
  }

  const imageIds = categories[category] || categories.drama
  const randomId = imageIds[Math.floor(Math.random() * imageIds.length)]

  return `${baseUrl}/${randomId}?w=${width}&h=${height}&fit=crop`
}

// 统一卡片数据结构
const createUnifiedCard = (overrides = {}) => {
  return {
    // 基础信息
    id: '@id',
    title: '@ctitle(6, 15)',
    cover: () => getRandomImage(150, 200, 'drama'),

    // 描述信息
    description: '@cparagraph(1, 2)',

    // 集数信息
    currentEpisode: '@integer(1, 50)',
    totalEpisodes: '@integer(12, 100)',

    // 统计信息
    plays: '@integer(1000, 1000000)',

    // 标签信息
    badge: {
      'type|1': ['new', 'hot', 'exclusive'],
      'text|1': ['新剧', '爆剧', '独播']
    },
    tags: ['@cword(2, 4)', '@cword(2, 4)'],
    category: '@cword(2, 4)',

    // 用户交互状态
    isLiked: '@boolean',
    isStarred: '@boolean',

    // 观看进度
    progress: '@integer(0, 100)',
    status: 'watching',

    // 时间信息
    lastWatchTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
    duration: '@integer(1800, 7200)', // 30分钟到2小时

    // 合并覆盖的字段
    ...overrides
  }
}

console.log('=== 测试统一字段结构 ===')

// 测试不同的场景
const testCases = [
  {
    name: '首页 - 在追列表',
    card: createUnifiedCard({
      id: '@id',
      title: '@ctitle(8, 15)',
      description: '观看至第' + '@integer(1, 50)' + '集',
      plays: null,
      badge: null,
      tags: [],
      category: null
    })
  },
  {
    name: '剧场页 - 剧集卡片',
    card: createUnifiedCard({
      id: '@id',
      title: '@ctitle(6, 15)',
      plays: '@integer(1000, 1000000)',
      badge: {
        'type|1': ['new', 'hot', 'exclusive'],
        'text|1': ['新剧', '爆剧', '独播']
      },
      currentEpisode: null,
      totalEpisodes: null,
      progress: null,
      status: null,
      lastWatchTime: null,
      duration: null
    })
  },
  {
    name: '追剧页 - 我的在追',
    card: createUnifiedCard({
      id: '@id',
      title: '@ctitle(8, 15)',
      description: '观看至第' + '@integer(1, 50)' + '集',
      plays: null,
      badge: null,
      tags: [],
      category: null,
      lastWatchTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
      duration: null
    })
  }
]

testCases.forEach((testCase, index) => {
  console.log(`\n📋 ${index + 1}. ${testCase.name}:`)
  const result = Mock.mock(testCase.card)
  console.log('字段列表:', Object.keys(result))
  console.log('核心字段:')
  console.log('  - id:', result.id)
  console.log('  - title:', result.title)
  console.log('  - cover:', typeof result.cover === 'string' ? '图片URL' : result.cover)
  console.log('  - currentEpisode:', result.currentEpisode)
  console.log('  - totalEpisodes:', result.totalEpisodes)
  console.log('  - isLiked:', result.isLiked)
  console.log('  - isStarred:', result.isStarred)
  console.log('  - plays:', result.plays)
  console.log('  - badge:', result.badge)
})

console.log('\n✅ 统一字段结构测试完成！')
console.log('所有卡片都包含相同的字段结构，但可以根据页面需求设置不同字段为null。')
